<?php

/**
* Class này cho phép tương tác với giao dịch Bảo Kim
*
* DETAIL: http://hq.lab.baokim.vn/projects/core/wiki/Transaction_API_Get
*
* @author hanv <hanv9488@gmail.com>
*
* @property string verify_transaction_by	mã xác minh o: OTP, p: password
*
*/
class Log extends RestModel
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	function restBaseUrl() { return BASE_DOMAIN . '/transactions/rest/transaction_api/get'; }
	/**
	 * @inheritdoc
	 */
	public function attributeNames()
	{
		return array(
			'verify_transaction_by',
			'transaction_status_id',
		);
	}

	/**
	* @inheritdoc
	*
	*/
	public function callers()
	{
		return CMap::mergeArray(parent::callers(), array(
			'sendLog'=>array(
				'class'=>'RESTCaller',
				'url'=>LOG_DOMAIN . '/post/index',
				'httpUsername'=>CORE_API_HTTP_USR,
				'httpPassword'=>CORE_API_HTTP_PWD,
				'rsaPrivateKey'=>CORE_API_RSA_PRIVATE_KEY,

				'logModelClass'=>'CoreRestApiLog',
				'logRequest'=>true,
			),
		));

	}
    /**
    * Check OTP giao dịch
    * DETAIL: http://hq.lab.baokim.vn/projects/core/wiki/Account_payment_api_Verify_by_otp
    *
    * @param mixed $transactionId
    * @param mixed $otp
    */
	public function sendLog($kind_id,$real_id, $name, $created_by, $comment, $value)
	{
		$restCaller = $this->getCaller('sendLog');
		$data = $restCaller->post(array(
			'kind_id' => $kind_id,
			'real_id' => $real_id,
			'name' => $name,
			'created_by' => $created_by,
			'comment' => $comment,
			'value' => $value,
		));

		$code = $restCaller->getCode();
		if ($code == 200) return true;
		if($code == 450) return false;

		return null;
	}
}
